/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Structural.Flyweight;

import java.util.HashMap;

/**
 *
 * @author Demoni
 */

public class Factory {

    private static int hits = 0;
    private static int recursos = 0;
    
    private static final HashMap recursosPorUri = new HashMap();
    
    public static Flyweight dameRecurso(String nombre){
        
        Flyweight recurso = (Flyweight)recursosPorUri.get(nombre);
        if(recurso==null){
            
            int tamaño = 12;
            recurso = new Flyweight(nombre, tamaño);
            Factory.logRecursos();
            recursosPorUri.put(nombre, recurso);
            System.out.println("--> Instancia de Recurso Creada: " + nombre);
        }
        return recurso;
    }
    
    public static void logHit(){
        hits++;
    }
    public static void logRecursos(){
        recursos++;
    }
    
    public static void mostrarEstadisticas(){
        System.out.println("Estadisticas: hits: " + hits + " Instancias: " + recursos);
    }
}